package com.pdsu.xpf.graduation01.service.impl;

import com.pdsu.xpf.graduation01.dao.UserDao;
import com.pdsu.xpf.graduation01.domain.Admin;
import com.pdsu.xpf.graduation01.domain.FeedBack;
import com.pdsu.xpf.graduation01.domain.User;
import com.pdsu.xpf.graduation01.service.IUserService;
import com.pdsu.xpf.graduation01.vo.UserVO;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class UserServiceImpl implements IUserService {


    final
    UserDao userDao;

    public UserServiceImpl(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public List<User> findAllUser() {

        return userDao.findAllUser();
    }

    @Override
    public User findUserByUsernameAPassword(String Username, String Password) {
        return userDao.findUserByUsernameAPassword(Username,Password);
    }

    @Override
    public int upDateUserTokenByUserID(String token, int uid) {
        return userDao.upDateUserTokenByUserID(token,uid);
    }

    @Override
    public User findUserByUsername(String Username) {
        return userDao.findUserByUsername(Username);
    }

    @Override
    public int insertUser(User user) {

        SimpleDateFormat sm= new SimpleDateFormat("yyyy-MM-dd HH:mm");

        String date = sm.format(new Date());
        return userDao.insertUser(user.getUsername(),user.getName(),user.getPassword(),user.getPhone(),user.getToken(),date);
    }

    @Override
    public User findUserByUID(int uid) {
        return userDao.findUserByUID(uid);
    }

    @Override
    public List<UserVO> findAllUserVO() {
        return userDao.findAllUserVO();
    }

    @Override
    public List<FeedBack> findAllFeedBack() {
        return userDao.findAllFeedBack();
    }

    @Override
    public Integer delFeedBackByFID(int fid) {
        return userDao.delFeedBackByFID(fid);
    }

    @Override
    public List<UserVO> searchUserByKey(String key) {
        return userDao.searchUserByKey(key);
    }

    @Override
    public List<Admin> adminLogin(String name, String password) {
        return userDao.adminLogin(name, password);
    }

    @Override
    public Integer addFeedBack(String fname, String msg, String uid, String phone, String date) {
        return userDao.addFeedBack(fname,msg,uid,phone,date);
    }

    @Override
    public Integer updateUserDATEBYUID(int uid) {
        SimpleDateFormat sm= new SimpleDateFormat("yyyy-MM-dd HH:mm");

        String date = sm.format(new Date());
        return userDao.updateUserDATEBYUID(uid,date);
    }
}
